import 'package:get/get.dart';
import 'package:oramemo/core/controllers/device_controller.dart';
import 'package:oramemo/core/controllers/version_controller.dart';

import 'home_state.dart';

class HomeLogic extends GetxController {
  final DeviceController deviceController = Get.find<DeviceController>();
  final HomeState state = HomeState();
  static HomeLogic to = Get.find();

  String get currentDeviceId => state.currentDevice?.device?.id ?? '';

  int pageIndex = 0;

  @override
  void onInit() {
    super.onInit();
    Future.delayed(const Duration(seconds: 2), () {
      VersionController.to.requestVersion(false);
    });
  }

  Future<void> requestDevices() async {
    await deviceController.fetchDevices();
    if (deviceController.devices.isNotEmpty) {
      state.currentDevice = deviceController.devices[0];
    } else {
      // Get.toNamed(FacilityRouter.scanningPage);
    }
    update();
  }
}
